package com.snail.auth.service;

import com.snail.auth.dao.AuthSystemRep;
import com.snail.auth.entity.AuthSystem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class AuthSystemService {
    @Autowired
    private AuthSystemRep sysRep;

    public void save(AuthSystem entity) {
        sysRep.saveAndFlush(entity);
    }

    public void del(String id) {
        sysRep.deleteById(id);
    }

    public AuthSystem getByKey(String id) {
        Optional optional = sysRep.findById(id);
        if (optional.isPresent()) {
            return (AuthSystem) optional.get();
        }
        return null;
    }

    public List<AuthSystem> list() {
        return sysRep.findAll();
    }

    public Page<AuthSystem> list(Pageable pageable) {
        return sysRep.findAll(pageable);
    }


}